package com.qf.shopping.controll;

import com.qf.shopping.dto.MessageDTO.MessageDTO;
import com.qf.shopping.dto.MessageDTO.MessageProfileDTO;
import com.qf.shopping.service.MessageService;
import com.qf.shopping.vo.MessageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/message")
public class MessageControll {

    @Autowired
    private MessageService messageService=null;

    //获取所有管理列表
    @GetMapping("/messages")
    public String getList(Model model){
        List<MessageDTO> list=messageService.getList();
        model.addAttribute("messages",list);
        return "/message/list";
    }

    //添加
    @GetMapping("/addMessage")
    public String toaddMessage(){

        return "/message/add";
    }
    //已经接收到前段信息 还不知道如何处理

    @PostMapping("/messages")
    public String addMessage(MessageProfileDTO m){
        m.setUserId(1);
        messageService.addMessage(m);
        return "redirect:/message/messages";
    }
    //修改
    @GetMapping("/updateMessage/{id}")
    public String toupdateMessage(@PathVariable("id") Integer id,Model model){
        MessageDTO m=messageService.getMessageDTO(id);
        model.addAttribute("message",m);
        return "/message/update";
    }

    @PutMapping("/updateMessage")
    public String updateMessage(MessageProfileDTO m){
        messageService.updataMessage(m);
        return "redirect:/message/messages";
    }
    //删除
    @GetMapping("/deleteMassage/{id}")
    public String deleteMassage(@PathVariable("id") Integer id){
        messageService.deleteMessage(id);
        return "redirect:/message/messages";
    }
}
